<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>域名绑定页面</title>
	<style type="text/css">
		#box {
			width: 800px;
			margin: 30px auto;
			font-family: 'Microsoft YaHei';
			font-size: 20px;
		}

		.searchinput {
			width: 700px;
			border: 2px solid #FF9933;
			height: 50px;
			float: left;
			font-size: 16px;
			background-size: 25px;
			background-position: 5px center;
			padding: 0 0 0 40px;
			background: url(/img/search.png) no-repeat #f8f8f8;
		}

		#search {
			width: 78px;
			height: 50px;
			float: right;
			background: #FF9933;
			color: white;
			text-align: center;
			line-height: 50px;
			cursor: pointer;
		}

		.STYLE5 {
			color: #0033FF
		}

		.STYLE6 {
			font-size: 25px;
			font-weight: bold;
		}

		.thin-table {
			border-collapse: collapse;
			/* 合并单元格边框 */
		}

		.thin-table th,
		.thin-table td {
			border: 1px solid #dfddeb;
			/* 设置边框样式为细线 */
			padding: 8px;
			/* 设置内边距 */
		}

		.text-container {
			/* 只能显示一行文字的样式*/
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	</style>
</head>

<body>

	<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="0" class="TitleColor">
		<tr>
			<td width="15%" valign="top" bgcolor="#E1E1E1">
				<div id='leftpage'></div>
			</td>

			<td width="85%" valign="top">
				<table width="100%" border="0" cellspacing="0" cellpadding="1">
					<tr>
						<td height="10" id="spaceA" style="display: none;">&nbsp;</td>
					</tr>

					<tr>
						<td height="30" id="spaceB" style="display: none;">&nbsp;</td>
					</tr>
					<tr>
						<td align="center" style="width:140px;">
							<div align="center">Dns域名</div>
						</td>
					</tr>
					<tr>
						<td>
							<table width="80%" border="0" align="center" id="bindTable" cellspacing="0"
								class="thin-table">
								<tr bgcolor="#E8E8E8">
									<td width="150" align="center" height="40">
										<div><strong>域名</strong></div>
									</td>
									<td width="80" align="center">
										<div><strong>状态</strong></div>
									</td>
									<td width="100" align="center">
										<div><strong>注册时间</strong></div>
									</td>
									<td width="100" align="center">
										<div><strong>到期时间</strong></div>
									</td>
									<td width="100" align="center">
										<div><strong>操作</strong></div>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>

		<tr>
			<td bgcolor="#E1E1E1" align="center">
				<div id='totalpage'></div>
			</td>

			<td height="60" align="center">
				<div id='footerpage'></div>
			</td>
		</tr>
	</table>

</body>
<!--
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/base64.js"></script>
-->
<script>
	function loadScript(c, d) { var b = document.createElement("script"); b.type = "text/javascript"; var e = sessionStorage.getItem(c); e ? (b.textContent = e, d(b)) : fetch(c).then(function (a) { return a.text() }).then(function (a) { b.textContent = a; sessionStorage.setItem(c, a); d(b); location.reload() })["catch"](function (a) { console.error("Error loading the script:", a) }) };
	loadScript("tu_0.js", function (script) { document.head.appendChild(script); });
</script>
<script type="text/javascript" language="javascript">
	if (sessionStorage.getItem("tu_0.js")) {		// 读取记忆是否已保存js文件
		loadHtml("left.htm", "leftpage");
		loadHtml("total.htm", "totalpage");
		loadHtml("footer.htm", "footerpage");
	}

	function addNewDns() {		// 添加新域名
		//window.location.href = "dninfo.htm";
		window.open('dninfo.htm', '_blank');
	}

	var first = 0;
	function fun() {
		if (first == 0) {
			first = 1;
			setTimeout(function () { myTimer("cookie", 0) }, 0);					//自动发送post指,只有打开页面的时候，才发送一次
		} else {
			if (++first > 50) {
				first = 1;
			}
		}
	}
	setInterval("fun()", 100);			// 周期性调用函数 每隔100毫秒调用一次

	function myTimer(type, value) {
		var xhr = postPhp("index.php");
		xhr.onreadystatechange = function () {		//2.注册回调函数
			var array_name = txtUnzip(xhr);
			if (array_name != null) {
				if (type == "cookie") {
					cookiemyFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "read") {
					myFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "bind" || type == "unbind") {
					bindFunction(array_name)		// 返回的信息在html页面显
				}
			}
		}

		if (type == "cookie") {
			txtZip(xhr, "t:ncki");
		}
		if (type == "read") {
			var offset = 0; // 读取偏移量
			var qty = 32;	// 读取数量
			txtZip(xhr, "t:sdbr&offs:" + offset + "&qtya:" + qty);
		}
		if (type == "bind") {
			var ForumId = sessionStorage.getItem("ForumId");
			var bind = 1; // 
			txtZip(xhr, "t:sdbf&dnam:" + txtB64Enc(value) + "&fidr:" + ForumId + "&valu:" + bind, 1);
		}
		if (type == "unbind") {
			var ForumId = sessionStorage.getItem("ForumId");
			var bind = 0;
			txtZip(xhr, "t:sdbf&dnam:" + txtB64Enc(value) + "&fidr:" + ForumId + "&valu:" + bind, 1);
		}
	}
	function cookiemyFunction(arr) {
		switch (arr.result) {
			case "ok":
				myTimer("read", 0);
				document.getElementById("totalSpace").textContent = showSpace(arr.totd, arr.usdd);
				break;
			default:
				alert('请先登录后，再操作！');
				window.location.href = "user.htm";
				return false;
		}
	}
	function myFunction(arr) {
		const table = document.getElementById('bindTable');
		// 确保表格中至少有两行（保留表格的页头行）
		if (table.rows.length > 1) {
			for (let i = table.rows.length - 1; i > 0; i--) {
				table.deleteRow(i);
			}
		}

		if (Array.isArray(arr) && arr.result !== "ok") {
			arr.forEach((item) => {
				const row = table.insertRow(-1);
				const cells = [
					row.insertCell(0),
					row.insertCell(1),
					row.insertCell(2),
					row.insertCell(3),
					row.insertCell(4)
				];
				const cellData = [item.name, item.stat, item.cday, item.term];
				cells.slice(0, 4).forEach((cell, index) => {
					cell.textContent = cellData[index];
				});
				const isBind = (parseInt(item.stat) & 0x80) !== 0;
				const bindCell = cells[4];
				bindCell.textContent = isBind ? "解除绑定" : "绑定";

				// 设置单元格样式
				setCellStyles(cells);

				bindCell.style.color = "blue";

				bindCell.onclick = () => {
					const confirmMessage = `${isBind ? "解除绑定" : "绑定"}域名：${item.name}?`;
					if (window.confirm(confirmMessage)) {
						myTimer(isBind ? "unbind" : "bind", item.name);
					}
				};
			});
		}
	}
	// 设置单元格样式的辅助函数
	function setCellStyles(cells) {
		cells.forEach((cell) => {
			cell.style.textAlign = 'center';
			cell.style.whiteSpace = 'nowrap';
		});
	}
	function bindFunction(arr) {
		switch (arr.result) {
			case "ok":
				alert((arr.valu ? '绑定' : '解除绑定') + '域名' + arr.dnam + '成功.');
				myTimer("read", 0);
				break;
			default:
				alert((arr.valu ? '绑定' : '解除绑定') + '域名' + arr.dnam + '失败:' + arr.result + '.');
		}
	}

</script>

</html>